<script setup lang="ts">
import { ref,onBeforeUnmount} from 'vue'

const editIndex = ref(-1)
const tableData = [
  {
    modelName: 'qwen1.5-14b-chat',
    modelSpace: 'qwen',
    apiAddr: 'http://127.0.0.1:9997',
    apiToken: '*********'
  }
]

onBeforeUnmount(() => {
  editIndex.value = -1
})
</script>

<template>
  <div>
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column prop="modelName" label="模型名称" width="180">
        <template #default="scope">
          <span v-show="scope.$index !== editIndex">{{ scope.row.modelName }}</span>
          <el-input
            v-show="scope.$index === editIndex"
            v-model="scope.row.modelName"
          ></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="modelSpace" label="模型厂商" width="180">
        <template #default="scope">
          <span v-show="scope.$index !== editIndex">{{ scope.row.modelSpace }}</span>
          <el-input
            v-show="scope.$index === editIndex"
            v-model="scope.row.modelSpace"
          ></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="apiAddr" label="api地址">
        <template #default="scope">
          <span v-show="scope.$index !== editIndex">{{ scope.row.apiAddr }}</span>
          <el-input
            v-show="scope.$index === editIndex"
            v-model="scope.row.apiAddr"
          ></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="apiToken" label="api令牌">
        <template #default="scope">
          <span v-show="scope.$index !== editIndex">{{ scope.row.apiToken }}</span>
          <el-input
            v-show="scope.$index === editIndex"
            v-model="scope.row.apiToken"
          ></el-input>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="120">
        <template #default="scope">
          <el-button v-show="scope.$index !== editIndex" link type="primary" size="small"
                     @click="() => editIndex=scope.$index">
            修改
          </el-button>
          <el-button v-show="scope.$index === editIndex" link type="primary" size="small">
            保存
          </el-button>
          <el-button link type="danger" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<style scoped lang="less">

</style>
